package
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.Capabilities;
	import flash.text.TextField;
	
	/**
	 *图片效果
	 * @author Leo
	 */	
	
	[SWF(width="1024",height="768",backgroundColor="#FFffff")]
	public class someEffect extends Sprite
	{
		private var load:Loader;
		
		private var num:int=0;
		
		private var imgNum:int = 9 ; 
		
		private var vectorImg:Array=[];
		
		private var centerX:Number = /*Capabilities.screenResolutionX / 2*/500;
		private var centerY:Number = /*Capabilities.screenResolutionY / 3*/300;
		private var radiusX:Number = imgNum / 2 * 51;
		private var radiusY:Number = 21;//菜单高度
		private var angleDifference:Number = Math.PI * (360 / imgNum) / 180;
		private var angleSpeed:Number = 0;
		private var scaleSpeed:Number = 0.0002;
		
		private var text:TextField;
		
		public function someEffect()
		{
			text = new TextField;
			text.x = text.y = 200;
			text.text = num+'';
			addChild(text);
			for( var i:int = 0 ; i < imgNum ;i++)
			{
				load = new Loader();
				load.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
				load.load(new URLRequest(i+'.jpg'));
			}
		}
		
		private function completeHandler(e:Event):void
		{
			num++;
			text.text = num+'';
			var img:Bitmap = e.target.content as Bitmap;
			var mc:MovieClip = new MovieClip;
			img.width = img.height = 50;
			mc.addChild(img);
			vectorImg.push(mc);
			addChild(mc);
			var startingAngle:Number = angleDifference * num;
			mc.x = centerX + radiusX * Math.cos(startingAngle);
			mc.y = centerY + radiusY * Math.sin(startingAngle);
			mc.angle = startingAngle;
			if(num>= imgNum)
			{
				removeChild(text);
				addEventListener(Event.ENTER_FRAME, enterFrameHandler);
			}
		}
		
		private function enterFrameHandler(e:Event):void
		{
			angleSpeed = (mouseX - centerX) / 10000;
			for (var i:uint = 0; i < imgNum; i++)
			{
				var item:MovieClip = vectorImg[i];
				item.angle +=  angleSpeed;
				item.x = centerX + radiusX * Math.cos(item.angle);
				item.y = centerY + radiusY * Math.sin(item.angle);
				var dy:Number = centerY - item.y;
				item.scaleY = (dy / radiusY);
				if (item.y < centerY)
				{
					item.scaleY *=  2;
				}
				item.scaleX = item.scaleY;
				item.alpha = item.scaleY + 1.1;
			}
		}
	}
}